package cc.devclub.ftd.thread.lifecycle;

/**
 * @Author: loading
 * @Create: 2021-12-13 23:40
 * @Description:
 */
public class TestBlock {


    public static void main(String[] args) throws Exception {
        Counter c = new Counter();

        Thread t1 = new Thread(new Runnable() {
            public void run() {
                c.increase();
            }
        }, "t1线程");
        t1.start();

        Thread t2 = new Thread(new Runnable() {
            public void run() {
                c.increase();
            }
        }, "t2线程");
        t2.start();

        Thread.sleep(100); // 确保 t1 run已经得到执行
        System.out.println(t2.getState().equals(Thread.State.BLOCKED));
    }
}

class Counter {
    int counter;

    public synchronized void increase() {
        counter++;
        try {
            Thread.sleep(30000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}